package cn.yunhe.services.impl;

import cn.yunhe.dao.BookDao;
import cn.yunhe.entity.Book;
import cn.yunhe.services.IBookService;
import cn.yunhe.utils.SqlSessionFactoryUtil;
import net.sf.json.JSONArray;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class BookService implements IBookService {

    SqlSession session = SqlSessionFactoryUtil.getSession();
    BookDao bookDao = session.getMapper(BookDao.class);
    JSONArray jsonArray = new JSONArray();

    @Override
    public JSONArray getBookByName(String bname) {
        List<Book> list = bookDao.getBookByName(bname);
        jsonArray.addAll(list);
        return jsonArray;
    }

    @Override
    public JSONArray getBookByAuthor(String author) {
        List<Book> list = bookDao.getBookByAuthor(author);
        jsonArray.addAll(list);
        return jsonArray;
    }

    @Override
    public JSONArray getBookByPubl(String publ) {
        List<Book> list = bookDao.getBookByPubl(publ);
        jsonArray.addAll(list);
        return jsonArray;
    }
}
